package homework3;

public class GList<T> implements IGList<T> {
	T object;
	IGList<T> rest;

	public GList(T o, IGList<T> list) {
		this.object = o;
		this.rest = list;
	}

	@Override
	public IGList<T> addElt(T o) {
		return new GList<T>(o, this);
	}

	@Override
	public IGList<T> remElt(T o) {
		if (o.equals(object)) {
			return rest;
		}
		return new GList<T>(object, rest.remElt(o));
	}

	@Override
	public boolean hasElt(T o) {
		return o.equals(object) || rest.hasElt(o);
	}

	@Override
	public int size() {
		return 1 + rest.size();
	}
}
